﻿CREATE PROCEDURE [dbo].[UpdateCategoryRoleAccess]
	@CategoryRoleAccessId uniqueidentifier,
    @Permissions int,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE CategoryRoleAccess

	SET 

	 [Permissions] = @Permissions,
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE CategoryRoleAccessId = @CategoryRoleAccessId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM CategoryRoleAccess 

	WHERE CategoryRoleAccessId = @CategoryRoleAccessId

RETURN 0